package com.wxapp.sale.service.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.sale.api.pojo.vm.goodsSpec.PGoodSpecDetailListVm;
import com.wxapp.sale.api.pojo.vm.goodsSpec.PGoodSpecDetailVm;
import com.wxapp.sale.api.pojo.vm.goodsSpec.PGoodSpecPageVm;
import com.wxapp.sale.api.pojo.vm.goodsSpec.PGoodSpecSelectVm;
import com.wxapp.sale.api.pojo.vo.goodsSpec.QGoodSpecAddVo;
import com.wxapp.sale.api.pojo.vo.goodsSpec.QGoodSpecDetailUpdateVo;
import com.wxapp.sale.api.pojo.vo.goodsSpec.QGoodSpecPageVo;
import com.wxapp.sale.api.pojo.vo.goodsSpec.QGoodSpecUpdateVo;
import com.wxapp.sale.service.service.GoodsSpecService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lgl
 * @Description 商品分类管理表
 * @Datetime 2023/4/23 15:57
 * @Modified By
 */
@RestController
@RequestMapping("goods/spec")
@Tag(name = "商品分类管理")
@RequiredArgsConstructor
public class GoodsSpecController extends IBaseController {
    private final GoodsSpecService goodsSpecService;

    @PostMapping("add")
    @Operation(summary ="添加商品分类")
    public ResultVm<String> add(@Schema(hidden = true) @User UserVo userVo, @RequestBody @Validated QGoodSpecAddVo qGoodSpecAddVo) {
        return goodsSpecService.add(userVo, qGoodSpecAddVo);
    }

    @PutMapping("update")
    @Operation(summary ="更新商品分类")
    public ResultVm<String> update(@Schema(hidden = true) @User UserVo userVo, @RequestBody @Validated QGoodSpecUpdateVo qGoodSpecUpdateVo) {
        return goodsSpecService.update(userVo, qGoodSpecUpdateVo);
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary ="添加商品分类")
    public ResultVm<String> delete(@Schema(hidden = true) @User UserVo userVo, @PathVariable String id) {
        return goodsSpecService.delete(userVo, id);
    }

    @PutMapping("editDetail/{id}")
    @Operation(summary ="获取商品分类")
    public ResultVm<String> editDetail(@Schema(hidden = true) @User UserVo userVo,@PathVariable(value = "id") String id, @RequestBody List<QGoodSpecDetailUpdateVo> vo) {
        return goodsSpecService.editDetail(userVo,id, vo);
    }

    @GetMapping("detail/{id}")
    @Operation(summary ="获取商品详情")
    public ResultVm<PGoodSpecDetailVm> detail(@PathVariable String id) {
        return goodsSpecService.detail(id);
    }

    @PostMapping("page")
    @Operation(summary ="获取商品分页")
    public ResultVm<IPage<PGoodSpecPageVm>> page(@RequestBody QGoodSpecPageVo QGoodSpecPageVo, @Schema(hidden = true) @User UserVo userVo) {
        return goodsSpecService.page(QGoodSpecPageVo,userVo);
    }

    @GetMapping("detailList/{id}")
    @Operation(summary ="获取商品列表")
    public ResultVm<List<PGoodSpecDetailListVm>> detailList(@PathVariable String id, @Schema(hidden = true) @User UserVo userVo) {
        return goodsSpecService.detailList(id,userVo);
    }

    @GetMapping("selectSpec")
    @Operation(summary ="获取商品分类下拉框")
    public ResultVm<List<PGoodSpecSelectVm>> selectSpec(@RequestParam(value = "name", required = false) String name, @Schema(hidden = true) @User UserVo userVo) {
        return goodsSpecService.selectSpec(name,userVo);
    }

    @GetMapping("selectSpecDetail/{specId}")
    @Operation(summary ="获取商品分类下拉框")
    public ResultVm<List<PGoodSpecSelectVm>> selectSpecDetail(@PathVariable(value = "specId") String specId, @RequestParam(value = "name", required = false) String name, @Schema(hidden = true) @User UserVo userVo) {
        return goodsSpecService.selectSpecDetail(specId, name,userVo);
    }
}
